package xyz.fuqufyb.aec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.fuqufyb.aec.dao.ApiSystemparamMapper;
import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.entity.ApiSystemparam;
import xyz.fuqufyb.aec.service.IApiSystemparamService;

import java.util.List;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: ApiSystemparamServiceImpl
 * @date 时间: 2021/2/2 17:33
 */

@Service("IApiSystemparamService")
public class ApiSystemparamServiceImpl implements IApiSystemparamService {

    @Autowired
    private ApiSystemparamMapper apiSystemparamMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {

        int i = apiSystemparamMapper.deleteByPrimaryKey(id);

        if (i > 0) {

            return i;
        }
        return 0;
    }

    @Override
    public int insertSelective(ApiSystemparam record) {

        int i = apiSystemparamMapper.insertSelective(record);
        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public ApiSystemparam selectByPrimaryKey(Integer id) {
        ApiSystemparam apiSystemparam = apiSystemparamMapper.selectByPrimaryKey(id);
        if (apiSystemparam != null) {
            return apiSystemparam;

        }
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(ApiSystemparam record) {
        int i = apiSystemparamMapper.updateByPrimaryKeySelective(record);
        if (i > 0) {
            return i;
        }

        return 0;
    }

    @Override
    public TableResult getPageApiSystemparam(Map<String, Object> maps) {
        String page = (String) maps.get("page");
        String limit = (String) maps.get("limit");
        if (page != null && limit != null) {

            PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
            List<ApiSystemparam> list = apiSystemparamMapper.getPageApiSystemparam(maps);

            PageInfo<ApiSystemparam> pageInfo = new PageInfo<>(list);

            return TableResult.getTableResultSuccess(pageInfo.getTotal(), pageInfo.getList());
        }

        return TableResult.getTableResultError("参数不能为空");
    }

    @Override
    public int deleteBySystemparIds(List<Integer> asList) {

        int i = apiSystemparamMapper.deleteBySystemparIds(asList);

        if (i > 0) {
            return i;
        }
        return 0;
    }
}
